//
//  MailViewController.m
//  chongwu
//
//  Created by 隼目 on 2021/9/15.
//

#import "MailViewController.h"
#import "MailTableViewCell.h"
#import "AddressBookViewController.h"
#import "CashierViewController.h"
#import "MyPetViewController.h"
@interface MailViewController ()<MailDelegate,UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)BaseTableView *tableView;
@property(nonatomic,strong)UILabel *moneyLabel;
@property(nonatomic,strong)UIButton *agreementBtn;
@end

@implementation MailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *botoomView=[UIView new];
    [self.view addSubview:botoomView];
    [botoomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(143*_mainHeight);
        make.bottom.mas_equalTo(-TAB_BAR_HEIGHT);
    }];
    botoomView.backgroundColor=[UIColor whiteColor];
    [self creatBottomView:botoomView];
    
    self.tableView=[BaseTableView new];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(84);
        make.bottom.mas_equalTo(botoomView.mas_top).mas_equalTo(0);
    }];
    self.tableView.backgroundColor=[UIColor clearColor];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
}
-(void)creatBottomView:(UIView *)bottomView{
    self.moneyLabel=[UILabel new];
    [bottomView addSubview:self.moneyLabel];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(bottomView.mas_centerY).mas_equalTo(0);
        make.left.mas_equalTo(46*_mainWidth);
        make.right.mas_equalTo(-290*_mainWidth);
    }];
    NSString *titleStr=[NSString stringWithFormat:@"¥%@",@"236.00"];
    NSMutableAttributedString *titleAttri =  [[NSMutableAttributedString alloc] initWithString:titleStr];
    NSRange priceRange = [titleStr rangeOfString:[NSString stringWithFormat:@"¥"]];//匹配得到的下标
    NSRange priceRange2 = [titleStr rangeOfString:[NSString stringWithFormat:@"%@",@"236.00"]];//匹配得到的下标
    [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(30)] range:priceRange];
    [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(44,46,52,1) range:priceRange];
    [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-BoldOblique" size:autoScaleW(50)] range:priceRange2];
    [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(44,46,52,1) range:priceRange2];
    self.moneyLabel.attributedText=titleAttri;
    
    UILabel *label=[UILabel new];
    [bottomView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(79*_mainWidth);
        make.top.mas_equalTo(bottomView.mas_centerY).mas_equalTo(5*_mainHeight);
        make.right.mas_equalTo(self.moneyLabel);
        make.height.mas_equalTo(36*_mainHeight);
    }];
    label.text=@"阅读并同意《宠物运单契约条款》";
    label.textColor=rgba(144,149,165,1);
    label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
    
    
    self.agreementBtn=[UIButton new];
    [bottomView addSubview:self.agreementBtn];
    [self.agreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.moneyLabel);
        make.centerY.mas_equalTo(label);
        make.width.height.mas_equalTo(18*_mainWidth);
    }];
    self.agreementBtn.selected=NO;
    [self.agreementBtn setImage:[UIImage imageNamed:@"weixuanzhong"] forState:0];
    [self.agreementBtn addTarget:self action:@selector(selectAgreementBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *submitBtn=[UIButton new];
    [bottomView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(_mainWidth*236);
        make.height.mas_equalTo(87*_mainHeight);
    }];
    [submitBtn setTitle:@"下单" forState:0];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:0];
    submitBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(30)];
    
    [submitBtn layoutIfNeeded];
    submitBtn.layer.masksToBounds=YES;
    submitBtn.layer.cornerRadius=87*_mainHeight/2;
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = submitBtn.bounds;
    //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
    [submitBtn.layer insertSublayer:gradientLayer atIndex:0];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.colors = @[(__bridge id)rgba(255,159,0,1).CGColor,
                             (__bridge id)rgba(255,116,0,1).CGColor ,
                             (__bridge id)rgba(255,102,0,1).CGColor];
    //设置颜色分割点（范围：0-1）
    gradientLayer.locations = @[@(0),@(0.5), @(1.0f)];
    submitBtn.layer.shadowColor = rgba(196,50,0,0.36).CGColor;
    submitBtn.layer.shadowOffset = CGSizeMake(0,0);
    submitBtn.layer.shadowOpacity = 1;
    submitBtn.layer.shadowRadius = 4;
    [submitBtn addTarget:self action:@selector(selectPushToCashier) forControlEvents:UIControlEventTouchUpInside];
}
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden=YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBarHidden=NO;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MailTableViewCell *cell=[[MailTableViewCell alloc]init];
    cell.delegate=self;
    if (indexPath.row==0) {
        [cell creatTopView];
    }if (indexPath.row==1) {
        [cell creatBottomView];
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return  cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

   
    if (indexPath.row==0) {
        return 353*_mainHeight;
    }else if (indexPath.row==1) {
        return 548*_mainHeight+60*_mainHeight*2+10*_mainHeight;
    }
    return 0;
}
-(void)selectAgreementBtn:(UIButton *)btn{
    if (btn.selected) {
        btn.selected=NO;
        [self.agreementBtn setImage:[UIImage imageNamed:@"weixuanzhong"] forState:0];
    }else{
        btn.selected=YES;
        [self.agreementBtn setImage:[UIImage imageNamed:@"xuanzhong"] forState:0];
    }
}
-(void)selectPushToAddress:(NSInteger)index{
    AddressBookViewController *vc=[[AddressBookViewController alloc] init];
    vc.typeIndex=index;
    vc.isHidenDog=NO;
    [ZQTools pushRootViewController:self andNextController:vc];
}
-(void)selectPushToCashier{
    CashierViewController *vc=[[CashierViewController alloc] init];
    vc.isHidenDog=YES;
    [ZQTools pushRootViewController:self andNextController:vc];
}
-(void)selectPushToMyPet{
    MyPetViewController *vc=[[MyPetViewController alloc] init];
    vc.isHidenDog=NO;
    vc.typeIndex=1;
    [ZQTools pushRootViewController:self andNextController:vc];
}

-(void)selectTime{
    SelectTimeView *view=[SelectTimeView new];
    [self.view.window addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(0);
    }];
    [view creatView];
}
-(void)selectShipping{
    SelectView *view=[SelectView new];
    [self.view.window addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(0);
    }];
    view.tableArr=@[@{@"vule":@"空运"},@{@"vule":@"火车"},@{@"vule":@"大巴"},@{@"vule":@"专线"}];
    [view creatView];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
